package pressKey;

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;

/**
 * 鼠标自动控制类
 *
 * @author Stanley
 */
public class RobotOperation {
	public static void mouseOp(double startX, double startY, double secX, double secY, double endX, double endY,
			double timeInterval) {
		try {
			Robot rbt = new Robot();
			rbt.mouseMove((int) startX, (int) startY);// 移动到初始位置
			rbt.delay(100);// 休息0.1秒按鼠标
			rbt.mousePress(KeyEvent.BUTTON1_DOWN_MASK);// 按下鼠标
			// rbt.delay(1000);
			rbt.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK);// 放开鼠标
			rbt.delay((int) timeInterval);// 休息间隔时间
			rbt.mouseMove((int) secX, (int) secY);
			rbt.delay(100);
			rbt.mousePress(KeyEvent.BUTTON1_DOWN_MASK);
			// rbt.delay(1000);
			rbt.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK);
			rbt.delay((int) timeInterval);
			rbt.mouseMove((int) endX, (int) endY);
			rbt.delay(100);
			rbt.mousePress(KeyEvent.BUTTON1_DOWN_MASK);
			// rbt.delay(1000);
			rbt.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK);
			rbt.delay((int) timeInterval);
		} catch (AWTException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
